from rest_framework.generics import ListAPIView
from . import models
from . import serializers
from rest_framework.views import APIView
from rest_framework.generics import RetrieveAPIView,ListAPIView
from rest_framework.filters import OrderingFilter,SearchFilter
# from rest_framework.pagination import PageNumberPagination
from .pagination import ProductPageNumberPagination
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.mixins import ListModelMixin
from rest_framework.response import Response

class CountryView(RetrieveAPIView):
    queryset = models.Country.objects.filter(is_delete=False,is_show=True).all()
    serializer_class = serializers.CountryProductModelSerializer





class PlaceView(RetrieveAPIView):
    queryset = models.Place.objects.filter(is_delete=False,is_show=True).all()
    serializer_class = serializers.PlaceSerializer


class ProductListView(ListAPIView):
    queryset = models.Product.objects.filter(is_delete=False,is_show=True).all()
    serializer_class = serializers.ProductSerializers
    filter_backends = [OrderingFilter,SearchFilter,DjangoFilterBackend]
    pagination_class = ProductPageNumberPagination
    search_fields = ['title','desc']


    filter_fields = ['place','product_category','discount','id',]

class ProductRetrieve(RetrieveAPIView):
    queryset = models.Product.objects.filter(is_delete=False,is_show=True).all()
    serializer_class = serializers.ProductRetSerializers
